package org.harsh.common.crypt;

import org.harsh.common.Config;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;


/**
 * Created by liuhaibo on 2024/7/15.
 */
public class DesCrypt extends AbsCrypt{
    public DesCrypt() {
        cryptMode = "DES";
        DESKeySpec desKeySpec = null;
        try {
            desKeySpec = new DESKeySpec(Config.DEFAULT_KEY.getBytes(Config.DEFAULT_CHARSET));
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(cryptMode);
            secretKey = keyFactory.generateSecret(desKeySpec);
        } catch (InvalidKeyException e) {
            throw new RuntimeException(e);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (InvalidKeySpecException e) {
            throw new RuntimeException(e);
        }
    }
}
